/*
 ============================================================================
 Name		: StrLightSettingList.cpp
 Author	  : 
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CStrLightSettingList implementation
 ============================================================================
 */

#include <coemain.h>
#include "StrLightSettingList.h"
#include "LemonAssistant.hrh"
#include "Configuration.h"
#include "MacroUtil.h"
#include "Utils.h"
#include "LMConfigDef.h"
#include "LMFileDefine.h"
#include "CommonUtils.h"

CStrLightSettingList::CStrLightSettingList()
	{
	// No implementation required
	}

CStrLightSettingList::~CStrLightSettingList()
	{
	TBuf<4> color;
	color.AppendNum(iSelected);
	iConfig->Set(KStrLightColor, color);
		SAFE_DELETE(iConfig);
	}

CStrLightSettingList* CStrLightSettingList::NewLC()
	{
	CStrLightSettingList* self = new (ELeave) CStrLightSettingList();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

CStrLightSettingList* CStrLightSettingList::NewL()
	{
	CStrLightSettingList* self = CStrLightSettingList::NewLC();
	CleanupStack::Pop(); // self;
	return self;
	}

void CStrLightSettingList::ConstructL()
	{
	TFileName filename;
	GetAppPath(filename);
	filename.Append(KConfigFile);
	iConfig = CConfiguration::NewL(filename);

	TBuf<4> color;
	iConfig->Get(KStrLightColor, color);

	iSelected = CCommonUtils::StrToInt(color);
	}
// ---------------------------------------------------------------------------
// CStrLightSettingList::CreateSettingItemL()
// Creates setting item
// ---------------------------------------------------------------------------
//  	
CAknSettingItem* CStrLightSettingList::CreateSettingItemL(TInt aSettingId)
	{
	CAknSettingItem* settingItem = NULL;

	switch (aSettingId)
		{
		case EStraightLightSettingColor:
			settingItem = new (ELeave) CAknEnumeratedTextPopupSettingItem(
					aSettingId, iSelected);
			break;
		default:
			break;
		}

	return settingItem;
	}

// ---------------------------------------------------------------------------
// CStrLightSettingList::EditItemL()
// Edits setting item data.
// ---------------------------------------------------------------------------
//    
void CStrLightSettingList::EditItemL(TInt aIndex, TBool aCalledFromMenu)
	{
	TInt
			currentItem =
					((CAknSettingItemList*) this)->ListBox()->View()->CurrentItemIndex();
	CAknSettingItemList::EditItemL(currentItem, aCalledFromMenu);
	(*SettingItemArray())[aIndex]->UpdateListBoxTextL();
	(*SettingItemArray())[aIndex]->StoreL();

	}

TKeyResponse CStrLightSettingList::OfferKeyEventL(const TKeyEvent& aKeyEvent,
		TEventCode aType)
	{
	switch (aType)
		{
		case EEventKey:
			switch (aKeyEvent.iCode)
				{
				case EKeyLeftArrow:
				case EKeyRightArrow:
					return EKeyWasNotConsumed;
				}
			break;
		}
	return CAknSettingItemList::OfferKeyEventL(aKeyEvent,aType);
	}
